﻿using System;
using Engine;
using Engine.Graphics;
using Game;
namespace Mekiasm
{
    public class CheckboxWidget : CanvasWidget
    {
        public ImageWidget img1 = new ImageWidget() { Size = new Vector2(32), IsVisible = true, HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center };
        public ImageWidget img3 = new ImageWidget() { Size = new Vector2(32), IsVisible = false, HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center };
        public CanvasWidget Canvas = new CanvasWidget() { Size = new Vector2(35) };
        public BevelledRectangleWidget Bevelled = new BevelledRectangleWidget() { Size = new Vector2(32), BevelColor = Color.White, BevelSize = 1f, CenterColor = Color.Black };
        public bool IsCheck
        {
            get; set;
        }
        public Action CheckChange { get; set; }
        public LabelWidget LabelWidget = new LabelWidget() { Margin = new Vector2(38, 0), FontScale = 0.7f };
        public string Text
        {
            get { return LabelWidget.Text; }
            set { LabelWidget.Text = value; }
        }
        public CheckboxWidget(string text = "")
        {
            img1.Texture = ContentManager.Get<Texture2D>("Mekiasm/Gui/Button/checkmark");
            img3.Texture = ContentManager.Get<Texture2D>("Mekiasm/Gui/Button/checkmark_digital");
            Canvas.Children.Add(Bevelled);
            Canvas.Children.Add(img1);
            Canvas.Children.Add(img3);
            Children.Add(Canvas);
            Children.Add(LabelWidget);
            LabelWidget.Text = text;
            Size = new Vector2(35, 80);
        }
        public void SetText(string text)
        {
            LabelWidget.Text = text;
        }
        public override void Update()
        {
            if (Input.Click.HasValue)
            {
                Segment2 cli = Input.Click.Value;
                if (Canvas.HitTest(cli.Start) && Canvas.HitTest(cli.End))
                {
                    IsCheck = !IsCheck;
                    CheckChange?.Invoke();
                }
            }
            if (IsCheck) { img1.IsVisible = false; img3.IsVisible = true; }
            else { img1.IsVisible = true; img3.IsVisible = false; }
        }





    }
}
